package dao;

import domain.Adminitem;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import tools.JDBCUtils;
import view.Detile;

import java.sql.*;
import java.sql.Date;
import java.util.*;

/**
 * @author :wn
 * @program : 管家婆项目
 * @descript : 用户数据dao
 * @create :2020-06-13 22:38
 */

public class AdminDao {

    public static ObservableList<Adminitem> quary(Adminitem adminitem) throws SQLException,ClassNotFoundException {
        Button detile;
        ResultSet rs = null;
        Statement stmt = null;
        String url = "jdbc:mysql://localhost:3306/familybook?useSSL=false";
        Connection conn = JDBCUtils.getConnection(url);
        String sql = "select * from bill";
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        ObservableList<Adminitem>date1=FXCollections.observableArrayList();
        while (rs.next()) {
            Adminitem item=new Adminitem();
            String  number = rs.getString("id");
            item.setNumber(number);
            String  type = rs.getNString("taketype");
            item.setType(type);

            float money = rs.getFloat("money");
            item.setMoney(money);
            Date   date = rs.getDate("days");
            item.setDays(date);
            String descriptions = rs.getString("descriptions");
            item.setDescription(descriptions);
            detile=new Button("编辑");
            detile.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
                    Detile detile=new Detile();
                    try {
                        detile.start(new Stage());

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            item.setDetile(detile);
            date1.add(item);
        }
        return date1;
    }
}
